import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './api/mock'
import Cookies from 'js-cookie';
import *as echarts from 'echarts'
Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
//添加全局前置守卫
router.beforeEach((to, from, next) => {
  //判断token存在
  const token = Cookies.get('token')
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else if (token && to.name === 'login') {
    next({ name: 'home' })
  } else {
    next()
  }
})
new Vue({
  render: h => h(App),
  router,
  store,
  mounted(){
    store.commit('tabAbout/addMenu',router)
  }
}).$mount('#app')
